## RVM
rvm_lib_path = "#{`echo $rvm_path`.strip}/lib"
$LOAD_PATH.unshift(rvm_lib_path) unless $LOAD_PATH.include?(rvm_lib_path)
require 'rvm'

rvm_list = `rvm list`.gsub(Regexp.new("\e\\[.?.?.?m"), '')

current_ruby = rvm_list.match(/=> ([^ ]+)/)[1]
desired_ruby = ask("Please select RVM version: [#{current_ruby}]".cyan)
desired_ruby = current_ruby if desired_ruby.blank?

gemset_name = ask("Please name gemset: [#{@app_name}]".cyan)
gemset_name = @app_name if gemset_name.blank?

@env = RVM::Environment.new(desired_ruby)
@env.gemset_create(app_name)
@env.gemset_use!(app_name)

run "rvm #{desired_ruby} gemset create #{gemset_name} > /dev/null"

create_file '.rvmrc', "rvm use #{desired_ruby}@#{gemset_name}"

run "rvm rvmrc trust #{@app_path} > /dev/null"